package com.xyz.rok.tools.service.impl;

import com.xyz.rok.tools.constant.SystemCode;
import com.xyz.rok.tools.exception.TitleException;
import com.xyz.rok.tools.model.Title;
import com.xyz.rok.tools.model.User;
import com.xyz.rok.tools.model.request.DkpStatRequest;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.xyz.rok.tools.mapper.DkpMapper;
import com.xyz.rok.tools.model.Dkp;
import com.xyz.rok.tools.service.DkpService;
@Service
public class DkpServiceImpl implements DkpService{

    @Resource
    private DkpMapper dkpMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return dkpMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Dkp record) {
        return dkpMapper.insert(record);
    }

    @Override
    public int insertSelective(Dkp record) {
        return dkpMapper.insertSelective(record);
    }

    @Override
    public Dkp selectByPrimaryKey(Integer id) {
        return dkpMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Dkp record) {
        return dkpMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Dkp record) {
        return dkpMapper.updateByPrimaryKey(record);
    }

    @Override
    public Dkp selectBySerialNumber(String serialNumber) {
        return dkpMapper.selectBySerialNumber(serialNumber);
    }

    @Override
    public Dkp checkingDkp(DkpStatRequest dkpStatRequest) throws Exception{
        Dkp dkp = dkpMapper.checkingDkp(dkpStatRequest.getServerId());
        if (dkp == null) {
            throw new TitleException(SystemCode.DKP_NO_ERROR);
        }
        if (!dkpStatRequest.getDkpPassword().equals(dkp.getPassword())) {
            throw new TitleException(SystemCode.DKP_PASSWORD_ERROR);
        }
        return dkp;
    }

}
